﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace DACK_MHTTUD_0912008_0912493
{
    class clsXML
    {
        internal static void SaveStringXMLToFile(string strcontent, string pathfile, SaveFileDialog saveFileDialog1, string titile)
        {
            saveFileDialog1.Filter = "key file in RSA(*.rsakey)|*.rsakey";
            saveFileDialog1.Title = titile;
            saveFileDialog1.FileName = pathfile;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(strcontent);
                xdoc.Save(saveFileDialog1.InitialDirectory + saveFileDialog1.FileName);
            }
        }

        public static string GetStringXMLFromFile(string path_file)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(path_file);
            string xmlcontents = xdoc.InnerXml;
            return xmlcontents;
        }

        public static void SaveDigitalSignatureToFile(byte[] encryptedData, string pathfile, SaveFileDialog saveFileDialog1, string titile)
        {

            saveFileDialog1.Filter = "Digital signature in RSA(*.rsa)|*.rsa";
            saveFileDialog1.Title = titile;
            saveFileDialog1.FileName = pathfile;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllBytes(saveFileDialog1.InitialDirectory + saveFileDialog1.FileName, encryptedData);
            }
        }
    }
}
